<?php
// +----------------------------------------------------------------------
// | Author: heizai <876555425@qq.com>
// +----------------------------------------------------------------------
namespace plugins\hz_msg_borad\controller;
use cmf\controller\PluginBaseController;
use plugins\hz_msg_borad\model\PluginMessageModel;
use think\Db;

class DoController extends PluginBaseController
{

    // 留言提交
    public function addmsg(){
        $model = new PluginMessageModel();
        $data = $this->request->post();
        
        $result = $this->validate($data, "Post");

        if ($result !== true) {
            $res['code'] = 500;
            $res['message'] = $result;
            return json_encode($res);exit();
        }

        $res = array();
        $res['code'] = 200;
        $res['message'] = 'Successful message!';
        if ($this->request->isPost()) {
            $data['createtime'] = date('Y-m-d H:i:s');
            $result=$model->allowField(true)->save($data);
            if ($result!==false) {
                return json_encode($res);exit();
            } else {
                $res['code'] = 500;
                $res['message'] = 'The message failed!';
                return json_encode($res);exit();
            }
        }

    }

}
